<template>
  <div class="addWorld">
    <h1>新增世界</h1>
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="世界名称" prop="name">
        <el-input v-model="ruleForm.name"></el-input>
      </el-form-item>
      <el-form-item label="世界简述" prop="desc">
        <div>中文简述</div>
        <el-input type="textarea" v-model="ruleForm.desc"></el-input>
      </el-form-item>
      <!-- <el-form-item label="特殊资源" prop="resource">
        <el-radio-group v-model="ruleForm.resource">
          <el-radio label="线上品牌商赞助"></el-radio>
          <el-radio label="线下场地免费"></el-radio>
        </el-radio-group>
      </el-form-item> -->
      <el-form-item label="世界外形" prop="region">
        <el-select v-model="ruleForm.region" placeholder="请选择世界外形">
          <el-option label="区域一" value="shanghai"></el-option>
          <el-option label="区域二" value="beijing"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="resetForm('ruleForm')">取消</el-button>
        <el-button type="primary" @click="submitForm('ruleForm')"
          >创建</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      ruleForm: {
        name: "",
        region: "",
        type: [],
        desc: "",
      },
      rules: {
        name: [
          { required: true, message: "请输入世界名称", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        region: [
          { required: true, message: "请选择世界外形", trigger: "change" },
        ],
        desc: [{ required: true, message: "请填写世界简述", trigger: "blur" }],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert("submit!");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>
<style lang="scss" scoped>
.addWorld {
  width: 100%;
  height: 840px;
  border-radius: 4px;
  background: #fff;
  box-sizing: border-box;
  padding: 30px;
  h1 {
    margin-bottom: 30px;
    font-size: 20px;
    font-weight: normal;
  }
}
</style>
